package com.android.thought.badboys.PhoneBook;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnShowListener;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.android.thought.badboys.R;
import com.android.thought.badboys.Action.IPhoneBookAction;
import com.android.thought.badboys.Info.PhoneInfo;

public class ActionDialog extends Dialog implements android.view.View.OnClickListener, OnShowListener {

	PhoneInfo mInfo  =  null;
	IPhoneBookAction mAction = null;
	
	TextView mTextView_Info = null;
	boolean mIsSelection = false;
	
	public ActionDialog(Context context , IPhoneBookAction listener) {
		super(context);
		
		
		this.mAction = listener;
	}
	
	public void setData(PhoneInfo info, boolean isSelection) { 
		this.mInfo = info;
		this.mIsSelection = isSelection;
	}

	
	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		this.setOnShowListener(this);
		setTitle("전화번호 관리 항목");
		
		setContentView(R.layout.phonebook_action_dialog);
		
		this.mTextView_Info = (TextView ) this.findViewById(R.id.textview_phonebook_info);
		
		this.findViewById(R.id.btn_user_register).setOnClickListener(this);
		this.findViewById(R.id.btn_user_delete).setOnClickListener(this);
		this.findViewById(R.id.btn_book_delete).setOnClickListener(this);
		
		
	}
	
	

	@Override
	public void onClick(View v) {
		int id = v.getId();
		
		if ( id == R.id.btn_user_register ) { 
			this.mAction.onRegister(mInfo);
		} else if ( id == R.id.btn_user_delete ) { 
			this.mAction.onRemove(mInfo);
		} else if ( id == R.id.btn_book_delete) {
			this.mAction.onPhoneBookRemove(mInfo);
		}
		
		dismiss();		
	}

	@Override
	public void onShow(DialogInterface dialog) {
		if ( mTextView_Info != null && mInfo != null ) { 
			mTextView_Info.setText(mInfo.getName() +"의 연락처 관리");
		}
		
		// 관리 번호 삭제 ( 관리 연락처에서만 지원) 
		this.findViewById(R.id.btn_user_delete).setVisibility(mIsSelection ? View.VISIBLE : View.GONE);
		
		// 관리번호 등록 ( 전체 연락처에서만 등록 ) 
		this.findViewById(R.id.btn_user_register).setVisibility(mIsSelection ? View.GONE : View.VISIBLE);
		
		// 번호 삭제 ( 전체 연락처에서만 등록 ) 
		this.findViewById(R.id.btn_book_delete).setVisibility(mIsSelection ? View.GONE : View.VISIBLE);
		
	}
}